import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.apache.kafka.clients.consumer.KafkaConsumer;


import java.sql.SQLOutput;
import java.util.Arrays;
import java.util.Properties;


public class kfkConsumer {
    public static void main(String[] args) {


        Properties properties = new Properties();
        properties.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "123.56.187.176:9092");
//        properties.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "192.168.23.128:9092");
        properties.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringDeserializer");
        properties.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringDeserializer");
        properties.put(ConsumerConfig.GROUP_ID_CONFIG, "niit1234");
        properties.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");

        KafkaConsumer<String, String> kfkConsumer = new KafkaConsumer<String, String>(properties);

        //订阅topic的name
        kfkConsumer.subscribe(Arrays.asList("15test"));


//        192.168.23.128 niit
        //循环消费
        while (true){

            ConsumerRecords<String,String> conRecord = kfkConsumer.poll(5);

            for (ConsumerRecord<String,String>consumer:conRecord){
                System.out.println(" value is "+ consumer.value());
            }
        }
    }


    }